package com.zbw;

import org.omg.Messaging.SyncScopeHelper;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.SynchronousQueue;

public class ThreadRreadWriteLock {
    public static void main(String args[]){
        cache ccc=new cache();
        for(int i=1;i<=5;i++){
            final String ii=i+"";
            new Thread(()->{
                ccc.put(ii,"xxx");
            },String.valueOf(i)).start();
            new Thread(()->{
                ccc.get(ii);
            },String.valueOf(i)).start();
        }
    }
}

class cache{
    Map<String,Object> map=new HashMap();
    public void put(String key,String val){
        System.out.println(Thread.currentThread().getName()+"写入1");
        map.put(key,val);
        System.out.println(Thread.currentThread().getName()+"写入完毕");
    };
    public void get(String key){
        Object val=map.get(key);
        System.out.println(Thread.currentThread().getName()+"读取完毕");
    };
}